package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.OrderOperation;
import com.ruoyi.system.service.IOrderOperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单业务列表Controller
 * 
 * @author ruoyi
 * @date 2025-06-12
 */
@RestController
@RequestMapping("/operation")
public class OrderOperationController extends BaseController
{
    @Autowired
    private IOrderOperationService orderOperationService;

    /**
     * 待审批
     */
    @RequiresPermissions("order:operation:approvalPendingList")
    @GetMapping("/approvalPendingList")
    public TableDataInfo approvalPendingList(OrderOperation orderOperation)
    {
        startPage();
        List<OrderOperation> list = orderOperationService.approvalPendingList(orderOperation);
        return getDataTable(list);
    }

    /**
     * 我的已办
     */
    @RequiresPermissions("order:operation:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderOperation orderOperation)
    {
        startPage();
        List<OrderOperation> list = orderOperationService.selectOrderOperationList(orderOperation);
        return getDataTable(list);
    }

    /**
     * 导出订单业务列表列表
     */
    @RequiresPermissions("order:operation:export")
    @Log(title = "订单业务列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderOperation orderOperation)
    {
        List<OrderOperation> list = orderOperationService.selectOrderOperationList(orderOperation);
        ExcelUtil<OrderOperation> util = new ExcelUtil<OrderOperation>(OrderOperation.class);
        util.exportExcel(response, list, "订单业务列表数据");
    }

    /**
     * 获取订单业务列表详细信息
     */
    @RequiresPermissions("order:operation:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderOperationService.selectOrderOperationById(id));
    }

    /**
     * 新增订单业务列表：员工录入数量
     */
    @RequiresPermissions("order:operation:add")
    @Log(title = "订单业务列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderOperation orderOperation)
    {
        return toAjax(orderOperationService.insertOrderOperation(orderOperation));
    }

    /**
     * 修改订单业务列表:审批
     */
    @RequiresPermissions("order:operation:edit")
    @Log(title = "订单业务列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderOperation orderOperation)
    {
        return toAjax(orderOperationService.updateOrderOperation(orderOperation));
    }

    /**
     * 删除订单业务列表
     */
    @RequiresPermissions("order:operation:remove")
    @Log(title = "订单业务列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderOperationService.deleteOrderOperationByIds(ids));
    }
}
